define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('创建者用户id')},
                        {field: 'user.username', title: __('创建者用户名')},
                        {field: 'driver_id', title: __('Driver_id')},
                        {field: 'driverinfo.name', title: __('Driverinfo.name')},
                        {field: 'start_time_begin', title: __('Start_time_begin'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'create_by_driver', title: __('Create_by_driver'), searchList: {"0":__('Create_by_driver 0'),"1":__('Create_by_driver 1')}, formatter: Table.api.formatter.normal},
                        {field: 'type', title: __('Type'), searchList: {"monopoly":__('Type monopoly'),"share":__('Type share'),"cargo":__('Type cargo')}, formatter: Table.api.formatter.normal},
                        {field: 'has_monopoly', title: __('Has_monopoly'), searchList: {"0":__('Has_monopoly 0'),"1":__('Has_monopoly 1')}, formatter: Table.api.formatter.normal},
                        {field: 'has_share', title: __('Has_share'), searchList: {"0":__('Has_share 0'),"1":__('Has_share 1')}, formatter: Table.api.formatter.normal},
                        {field: 'has_cargo', title: __('Has_cargo'), searchList: {"0":__('Has_cargo 0'),"1":__('Has_cargo 1')}, formatter: Table.api.formatter.normal},
                        {field: 'order_num', title: __('Order_num')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7'),"8":__('Status 8'),"10":__('Status 10')}, formatter: Table.api.formatter.status},
                        {field: 'begin_time', title: __('Begin_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'cancel_time', title: __('Cancel_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});